﻿@model Fcom.VNInsurance.Web.Models.ProductLang
@{
    ViewBag.Title = "ManageProductByID";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
    
}
 <link rel="stylesheet" href="@Url.Content("~/Content/jqwidgets/styles/jqx.base.css")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcore.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdata.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxbuttons.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxscrollbar.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxmenu.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcheckbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxlistbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdropdownlist.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.sort.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.pager.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.selection.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.edit.js")"></script> 
<script type="text/javascript">
        $(document).ready(function () {
           
            var url = "@Url.Action("getJsonCPProduct","CompanyProduct", new {ID=Model.ProductID})";
            // prepare the data 
            //select new m.OneFare,m.InsuranceMoney
            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'CProductID', type: 'int' },
                    { name: 'DisplayName', type: 'string' },
        
                    { name: 'CompanyLogo', type: 'string' },
             { name: 'OneFare', type: 'int' },
              { name: 'InsuranceMoney', type: 'int' }
          
                ],
                id: 'CProductID',
                url: url
            };
           
            var imagerenderer = function (row, datafield, value) {
                return '<img style="margin:10px;10px;10px;10px;" height="100" width="100" src="/content/images/CompanyLogo/' + value + '"/>';
            }


            var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data, status, xhr) { },
                loadComplete: function (data) { },
                loadError: function (xhr, status, error) { }
            });
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 1150,
                source: dataAdapter,
                rowsheight: 100,
                // select new { m.Benefit,m.CProductID,m.DisplayName,m.Future,m.Intro,m.CompanyProduct.Company.CompanyName,m.CompanyProduct.Company.CompanyLogo,CompanyID=m.CompanyProduct.Company.ID};
                pageable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                editable: false,
                selectionmode: 'multiplecellsadvanced',
                columns: [
                  { text: 'ID', datafield: 'CProductID', width: 30 },
                  
                  { text: 'Tên sản phẩm', datafield: 'DisplayName', width: 500 },
                   { text: 'Công ty', datafield: 'CompanyLogo', width: 200, cellsrenderer: imagerenderer, height: 100 },
                
                    {
                        text: 'Quyền lợi', datafield: 'QL', columntype: 'button', width: 100, cellsrenderer: function () {
                            return "Ql";
                        }, buttonclick: function (editrow) {

                            var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                            window.location = "@Url.Action("CoverageCProductIDMN","CompanyProduct")/" + dataRecord.CProductID;
                     }
                    },
                   {
                       text: 'Tài liệu', datafield: 'QLTL', columntype: 'button', width: 100, cellsrenderer: function () {
                           return "QLTL";
                       }, buttonclick: function (editrow) {

                           var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                           window.location = "@Url.Action("CompanyProductDocs","CompanyProduct")/" + dataRecord.CProductID;
                     }
                   },
                    {
                        text: 'Hình Phiếu BH', datafield: 'QLH', columntype: 'button', width: 100, cellsrenderer: function () {
                            return "QLH";
                        }, buttonclick: function (editrow) {

                            var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                            window.location = "@Url.Action("CompanyProductPapers","CompanyProduct")/" + dataRecord.CProductID;
                       }
                    },
                  {
                     text: 'Chỉnh sửa', datafield: 'Edit', columntype: 'button', width: 100, cellsrenderer: function () {
                         return "Edit";
                     }, buttonclick: function (editrow) {

                         var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                         window.location = "@Url.Action("EditCompanyProduct","CompanyProduct")/" + dataRecord.CProductID;
                     }
                  },
                  {
                      text: 'Xóa', datafield: 'Xóa', columntype: 'button', width: 100, cellsrenderer: function () {
                          return "Xóa";
                      }, buttonclick: function (editrow) {

                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                          var rr = confirm("Bạn có muốn xóa \"" + dataRecord.DisplayName + "\" ?");
                          if (rr) {
                              $.ajax({
                                  type: "post",
                                  url: "@Url.Action("DeleteCPID","CompanyProduct")",
                                  data: { ID: dataRecord.ID },
                                  datatype: "json",
                                  success: function (rvdata) {
                                      if (rvdata.success) {
                                          $("#jqxgrid").jqxGrid({source:dataAdapter});
                                      }
                                  }

                              });
                          }//end rr

                      }
                  }
                ]                
            });
        });
    </script>
<div class="container" style="padding:10px;">
    <fieldset>
                 <legend >Quản lý sản phẩm @Model.DisplayName</legend>
   </fieldset>
    <br />
     @Html.ActionLink("Thêm sản phẩm", "AddCompanyProduct", "CompanyProduct", new { ID=Model.ProductID},null)<br />
    <br />

   <div id="jqxgrid" class="container">

   </div>
</div>
